package com.hwg.emp.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hwg.emp.dto.EmpDTO;
import com.hwg.emp.model.DeptMD;
import com.hwg.emp.model.UserMD;
import com.hwg.emp.service.DeptService;
import com.hwg.emp.service.EmployeeService;
import com.hwg.emp.service.ServiceFactroy;

public class SelectOwnInfoController extends HttpServlet{
	
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			UserMD currentUser = (UserMD)req.getSession().getAttribute("USER");
			String id = currentUser.getId();
			resp.setCharacterEncoding("UTF-8");
			EmployeeService employeeService=ServiceFactroy.getService(EmployeeService.class);
			DeptService deptService=ServiceFactroy.getService(DeptService.class);
			EmpDTO empDto=employeeService.selectOwnInfoById(id);
			DeptMD dept = deptService.getDeptById(empDto.getDept().getId());
			empDto.setDept(dept);
			req.setAttribute("empDto", empDto);
			req.getRequestDispatcher("/pages/employeeInfoShow.jsp").forward(req, resp);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
